﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using Extensil.Common;
using Extensil.Processor;
//using Extensil.Processor.General;

namespace Extensil.Category.Settings
{
    [Extensil.Common.CategoryAttribute("Settings")]
    public partial class SettingsForm :BaseCategory
    {
        bool _isReloading = false;
        public SettingsForm()
        {
            InitializeComponent();
        }
        protected override void OnLoad(EventArgs e)
        {
            LoadCategories();
        }
        public void Reload()
        {
            _isReloading = true;
            LoadCategories();
        }
        void LoadCategories()
        {
            List<ComboPropertyParam> ds = CategoryFactory.GetCategoriesWithSetting();
            ds.Insert(0, new ComboPropertyParam("Main", "Main"));
            cbCategories.DisplayMember = "Key";
            cbCategories.ValueMember = "Value";
            cbCategories.DataSource = ds;
        }
        private void cbCategories_SelectedIndexChanged(object sender, EventArgs e)
        {
            if(_isReloading)
            {
                _isReloading = false;
                return;
            }
            UserForm uForm = new UserForm();
            if(cbCategories.SelectedValue.ToString() == "Main")
            {
                uForm = new CategorySetting();
            }
            else
            {
                uForm = CategoryFactory.GetCategoryForm(cbCategories.SelectedValue.ToString()).Setting;
            }
            LoadForm(uForm);
        }
        void LoadForm(UserForm frm)
        {
            frm.TopLevel = false;
            frm.Dock = DockStyle.Fill;
            frm.FormBorderStyle = FormBorderStyle.None;
            frm.Show();
            splitContainer1.Panel2.Controls.Clear();
            splitContainer1.Panel2.Controls.Add(frm);
        }
        
    }
}
